/*
 * Copyright (c) 2014-2024 Stream.io Inc. All rights reserved.
 *
 * Licensed under the Stream License;
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    https://github.com/GetStream/stream-video-android/blob/main/LICENSE
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.gitee.wsl.compose.ui.theme.style

import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle


/**
 * Wrapper for the platform text style.
 */
 data class TextStyleWrapper(
     val platform: TextStyle,
) : UiStyle

/**
 * Stream text style
 */
 data class UiTextStyle(
    override val default: TextStyleWrapper,
    override val disabled: TextStyleWrapper,
    override val pressed: TextStyleWrapper,
) : UiStateStyle<TextStyleWrapper>


 open class TextStyleProvider {

     @Composable
     fun defaultLabel(
         size: UiStyleSize = UiStyleSize.L,
         default: TextStyleWrapper = when (size) {
             UiStyleSize.XS, UiStyleSize.S -> MaterialTheme.typography.labelSmall.wrapper()
             UiStyleSize.M -> MaterialTheme.typography.labelMedium.wrapper()
             else -> MaterialTheme.typography.labelLarge.wrapper()
         },
         pressed: TextStyleWrapper = default,
         disabled: TextStyleWrapper = default.disabledAlpha(),
     ): UiTextStyle = UiTextStyle(default, disabled, pressed)

    @Composable
    fun defaultButtonLabel(
        size: UiStyleSize = UiStyleSize.L,
        default: TextStyleWrapper = when (size) {
            UiStyleSize.XS, UiStyleSize.S -> MaterialTheme.typography.labelSmall.wrapper()
            UiStyleSize.M -> MaterialTheme.typography.labelMedium.wrapper()
            else -> MaterialTheme.typography.labelLarge.wrapper()
        },
        pressed: TextStyleWrapper = default,
        disabled: TextStyleWrapper = default.disabledAlpha(),
    ): UiTextStyle = UiTextStyle(default, disabled, pressed)

    /*@Composable
     fun defaultTitle(
        size: StyleSize = StyleSize.L,
        default: TextStyleWrapper = when (size) {
            StyleSize.XS -> VideoTheme.typography.titleXs.wrapper()
            StyleSize.S -> VideoTheme.typography.titleS.wrapper()
            StyleSize.M -> VideoTheme.typography.titleM.wrapper()
            else -> VideoTheme.typography.titleL.wrapper()
        },
        pressed: TextStyleWrapper = default,
        disabled: TextStyleWrapper = default.disabledAlpha(),
    ): StreamTextStyle = StreamTextStyle(default, disabled, pressed)

    @Composable
     fun defaultSubtitle(
        size: StyleSize = StyleSize.M,
        default: TextStyleWrapper = when (size) {
            StyleSize.XS -> VideoTheme.typography.subtitleS.wrapper()
            StyleSize.S -> VideoTheme.typography.subtitleS.wrapper()
            StyleSize.M -> VideoTheme.typography.subtitleM.wrapper()
            else -> VideoTheme.typography.subtitleL.wrapper()
        },
        pressed: TextStyleWrapper = default,
        disabled: TextStyleWrapper = default.disabledAlpha(),
    ): StreamTextStyle = StreamTextStyle(default, disabled, pressed)

    @Composable
     fun defaultBody(
        size: StyleSize = StyleSize.L,
        default: TextStyleWrapper = when (size) {
            StyleSize.XS, StyleSize.S, StyleSize.M -> VideoTheme.typography.bodyM.wrapper()
            else -> VideoTheme.typography.bodyL.wrapper()
        },
        pressed: TextStyleWrapper = default,
        disabled: TextStyleWrapper = default.disabledAlpha(),
    ): StreamTextStyle = StreamTextStyle(default, disabled, pressed)

    @Composable
     fun defaultBadgeTextStyle(
        default: TextStyleWrapper = VideoTheme.typography.labelXS.wrapper(),
        pressed: TextStyleWrapper = default,
        disabled: TextStyleWrapper = default.disabledAlpha(),
    ): StreamTextStyle = StreamTextStyle(default, disabled, pressed)

    @Composable
     fun defaultTextField(
        size: StyleSize = StyleSize.M,
        default: TextStyleWrapper = when (size) {
            StyleSize.XS -> VideoTheme.typography.subtitleS.withColor(VideoTheme.colors.basePrimary)
            StyleSize.S -> VideoTheme.typography.subtitleS.withColor(VideoTheme.colors.basePrimary)
            StyleSize.M -> VideoTheme.typography.subtitleM.withColor(VideoTheme.colors.basePrimary)
            else -> VideoTheme.typography.subtitleL.withColor(VideoTheme.colors.basePrimary)
        },
        pressed: TextStyleWrapper = default,
        disabled: TextStyleWrapper = default.disabledAlpha(),
    ): StreamTextStyle = StreamTextStyle(default, disabled, pressed)*/
}

 object StreamTextStyles : TextStyleProvider()

// Utilities
internal fun TextStyle.wrapper(): TextStyleWrapper = TextStyleWrapper(platform = this)

internal fun TextStyle.withColor(color: Color) = TextStyleWrapper(
    platform = this.copy(
        color = color,
    ),
)

internal fun TextStyleWrapper.withAlpha(alpha: Float): TextStyleWrapper = this.platform.copy(
    color = this.platform.color.copy(
        alpha = alpha,
    ),
).wrapper()

internal fun TextStyleWrapper.disabledAlpha() = this.withAlpha(0.16f)
